<?php

namespace App\Package\Finance\Traits;

use App\Package\Finance\Contracts\ElementContract;
use App\Package\Finance\Contracts\OperandContract;
use App\Package\Finance\Contracts\OperatorContract;

/**
 * 表达式处理逻辑
 *
 * Trait ExpressionHandler
 * @package App\Package\Finance\Traits
 * Date: 2018/6/7
 * @author George
 */
trait ExpressionHandler
{
	/**
	 * 解析字面量
	 *
	 * Date: 2018/6/6
	 * @author George
	 * @return mixed
	 */
	public function analysis()
	{

	}

	/**
	 * 执行解析结果
	 *
	 * Date: 2018/6/6
	 * @author George
	 * @return mixed
	 */
	public function execute()
	{

	}

	/**
	 * Date: 2018/6/7
	 * @author George
	 * @param ElementContract $element
	 */
	public function judgeElement(ElementContract $element)
	{
		$this->isOperand($element);
		$this->isOperator($element);
	}

	/**
	 * 判断是否为表达式操作数
	 *
	 * Date: 2018/6/7
	 * @author George
	 * @param ElementContract $element
	 * @return bool|mixed
	 */
	public function isOperand(ElementContract $element)
	{
		if ($element instanceof OperandContract) {
			return $element->value;
		}
		return false;
	}

	/**
	 * 判断是否为表达式操作符
	 *
	 * Date: 2018/6/7
	 * @author George
	 * @param ElementContract $element
	 * @return bool
	 */
	public function isOperator(ElementContract $element)
	{
		if ($element instanceof OperatorContract) {
			return true;
		}
		return false;
	}
}
